<html>
<head><meta charset="utf-8"><title>Generator optimization for locals that may not become live · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html">Generator optimization for locals that may not become live</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="167988511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167988511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167988511">(Jun 12 2019 at 21:10)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> <span class="user-mention" data-user-id="116883">@tmandry</span></p>



<a name="167988530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167988530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167988530">(Jun 12 2019 at 21:10)</a>:</h4>
<p>context is allowing something like this optimization: <a href="https://github.com/rust-lang/rust/issues/59123#issuecomment-501089032" target="_blank" title="https://github.com/rust-lang/rust/issues/59123#issuecomment-501089032">https://github.com/rust-lang/rust/issues/59123#issuecomment-501089032</a></p>



<a name="167988553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167988553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167988553">(Jun 12 2019 at 21:11)</a>:</h4>
<p>and carving out a rule that could ban <a href="https://github.com/rust-lang/rust/issues/59123#issuecomment-501437202" target="_blank" title="https://github.com/rust-lang/rust/issues/59123#issuecomment-501437202">https://github.com/rust-lang/rust/issues/59123#issuecomment-501437202</a></p>



<a name="167988585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167988585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167988585">(Jun 12 2019 at 21:11)</a>:</h4>
<p>I think <span class="user-mention" data-user-id="116883">@tmandry</span> is interested in looking at steps in the direction of a memory model that we could take that would allow this without committing to a full model</p>



<a name="167988598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167988598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167988598">(Jun 12 2019 at 21:11)</a>:</h4>
<p>obv. this would have to go through the RFC process and get aired thoroughly in this group</p>



<a name="167988667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167988667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167988667">(Jun 12 2019 at 21:12)</a>:</h4>
<p>but I figured I'd start the topic here for discussion</p>



<a name="167988994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167988994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167988994">(Jun 12 2019 at 21:16)</a>:</h4>
<p>One question on my mind is how/if we could find crates impacted by this</p>



<a name="167989058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167989058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167989058">(Jun 12 2019 at 21:17)</a>:</h4>
<p>e.g. is there a way to do a crater run with miri validation enabled? Have we ever tried?</p>



<a name="167990913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167990913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167990913">(Jun 12 2019 at 21:39)</a>:</h4>
<p>not really currently but if it's strongly desired perhaps feasible in about 2-4 weeks (cc <span class="user-mention" data-user-id="121055">@Pietro Albini</span>)</p>



<a name="167990994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167990994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pietro Albini <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167990994">(Jun 12 2019 at 21:40)</a>:</h4>
<p>wasn't miri <em>really</em> slow?</p>



<a name="167991057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167991057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pietro Albini <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167991057">(Jun 12 2019 at 21:41)</a>:</h4>
<p>like, a test run now takes 4-5 days, if we run it with miri how long is it going to take :/</p>



<a name="167995687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167995687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167995687">(Jun 12 2019 at 22:45)</a>:</h4>
<p><span class="user-mention" data-user-id="121055">@Pietro Albini</span> about 1000 times that maybe <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="167996264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167996264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pietro Albini <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167996264">(Jun 12 2019 at 22:53)</a>:</h4>
<p>eeek <em>no</em></p>



<a name="167996584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167996584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167996584">(Jun 12 2019 at 22:58)</a>:</h4>
<p>yeah, that's unfortunate. what kind of machine are we running crater on <span class="user-mention" data-user-id="121055">@Pietro Albini</span>?</p>



<a name="167996624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167996624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167996624">(Jun 12 2019 at 22:59)</a>:</h4>
<p>is this doc still accurate? <a href="https://github.com/rust-lang-nursery/crater/blob/master/docs/agent-machine-setup.md" target="_blank" title="https://github.com/rust-lang-nursery/crater/blob/master/docs/agent-machine-setup.md">https://github.com/rust-lang-nursery/crater/blob/master/docs/agent-machine-setup.md</a></p>



<a name="167996905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167996905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167996905">(Jun 12 2019 at 23:03)</a>:</h4>
<p><span class="user-mention" data-user-id="116883">@tmandry</span> mostly, yes</p>



<a name="167996926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167996926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167996926">(Jun 12 2019 at 23:03)</a>:</h4>
<p>machine-spec wise anyway</p>



<a name="167996942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167996942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167996942">(Jun 12 2019 at 23:03)</a>:</h4>
<p>although we might've downgraded to 1 terabyte recently not sure</p>



<a name="167997334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167997334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pietro Albini <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167997334">(Jun 12 2019 at 23:09)</a>:</h4>
<p>we dowgraded from 4tb to 2tb, so that page is fully accurate</p>



<a name="167997604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/167997604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pietro Albini <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#167997604">(Jun 12 2019 at 23:12)</a>:</h4>
<p><span class="user-mention" data-user-id="116883">@tmandry</span> a c5.2xlarge is 8 cores at ~3ghz</p>



<a name="168024415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168024415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168024415">(Jun 13 2019 at 08:20)</a>:</h4>
<p>well also the vast majority of crates probably wont work in Miri for various reasons</p>



<a name="168024428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168024428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168024428">(Jun 13 2019 at 08:20)</a>:</h4>
<p>most of them for trying to communicate with the host system in any way (network, file system, system clock, C FFI, ...)</p>



<a name="168024783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168024783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168024783">(Jun 13 2019 at 08:26)</a>:</h4>
<blockquote>
<p>I think <span class="user-mention silent" data-user-id="116883">tmandry</span> is interested in looking at steps in the direction of a memory model that we could take that would allow this without committing to a full model</p>
</blockquote>
<p>the good news is that (I think) "though shall not write through (frozen) shared references" is pretty much the least controversial part of stacked borrows. every violation of that that we found so far was a blatant typo.</p>
<p>However, this does interact with <a href="https://github.com/rust-lang/rust/issues/56604" target="_blank" title="https://github.com/rust-lang/rust/issues/56604">https://github.com/rust-lang/rust/issues/56604</a>: is it allowed to write through a raw pointer obtained by turning an <code>&amp;mut T</code> into a <code>*const T</code>? Current Miri says no.</p>



<a name="168050122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168050122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168050122">(Jun 13 2019 at 14:28)</a>:</h4>
<p>Is there a possibility for a "fast" mode with Miri that could tell you if a program run would exceed Miri's abilities? Valgrind has a no-op mode (only 50% the original programs speed!) in a similar vein.</p>
<p>If so, you could run "miri check-effectiveness" on all the crates, establish a blacklist for those which don't pass, and then make a decision on whether to run on the remainder.</p>



<a name="168050165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168050165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168050165">(Jun 13 2019 at 14:29)</a>:</h4>
<p>You could also sample crates to get <em>some</em> amount of testing</p>



<a name="168051173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168051173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168051173">(Jun 13 2019 at 14:40)</a>:</h4>
<p>Miri's "fast mode" is <code>-Zmiri-disable-validation</code>. The overhead there is just around 300x-500x, not 1000x...</p>



<a name="168051236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168051236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168051236">(Jun 13 2019 at 14:41)</a>:</h4>
<p>there is also probably a lot of optimization potential there. Like, I have not even profiled Miri. I don't have the resources for that so it is not something I focus on.</p>



<a name="168051307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168051307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168051307">(Jun 13 2019 at 14:42)</a>:</h4>
<p>so, this needs someone who is willing to dedicate some time to look into how to make Miri faster. Without sacrificing readability or code organization, because correctness is still crucial. But even then, I would not expect it to become more than 10x faster -- so still way too slow. oky, much of crater's time is probably spent building, not running tests, so that one does not multiply.</p>



<a name="168051452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168051452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168051452">(Jun 13 2019 at 14:43)</a>:</h4>
<p>more realistically, I actually talked with Julian about having a valgrind module for Stacked Borrows. We think it's possible. But I won't have the time to do it.</p>



<a name="168054790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168054790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168054790">(Jun 13 2019 at 15:18)</a>:</h4>
<p>Any particular reason for the valgrind preference over sanitizers? I remember asking this before, but I don't remember the answer</p>



<a name="168055753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168055753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168055753">(Jun 13 2019 at 15:28)</a>:</h4>
<p>If we want to make UB detection only 2x-10x slower, we are probably having to be able to build "self-instrumented" binaries directly, e.g., have MIR passes that inserts <code>assert!</code>s for UB violations into the MIR, and then lower the "self-instrumented" MIR to LLVM-IR and optimize it properly.</p>
<p>This could allow people to build "fortified" binaries that <code>panic!</code> before invoking undefined behavior with minimal performance impact. I don't think we can make the "evaluator" approach that miri uses fast, unless we essentially transform it into a tool that does the above.</p>



<a name="168056682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168056682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168056682">(Jun 13 2019 at 15:38)</a>:</h4>
<blockquote>
<p>Any particular reason for the valgrind preference over sanitizers? I remember asking this before, but I don't remember the answer</p>
</blockquote>
<p>valgrind is something I have used before, sanitizers not. valgrind could also work when linking with unmodified C code.</p>



<a name="168056714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168056714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168056714">(Jun 13 2019 at 15:38)</a>:</h4>
<p>and anyway the Rust code would need some instrumentation so its more of a valgrind-sanitizer hybrid</p>



<a name="168056741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168056741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168056741">(Jun 13 2019 at 15:39)</a>:</h4>
<blockquote>
<p>valgrind could also work when linking with unmodified C code.</p>
</blockquote>
<p>It would, but you probably don't want to apply Rust validation to it.</p>



<a name="168056753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168056753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168056753">(Jun 13 2019 at 15:39)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> aren't you describing a sanitizer?</p>



<a name="168056791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168056791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168056791">(Jun 13 2019 at 15:39)</a>:</h4>
<blockquote>
<blockquote>
<p>valgrind could also work when linking with unmodified C code.</p>
</blockquote>
<p>It would, but you probably don't want to apply Rust validation to it.</p>
</blockquote>
<p>I think you do! When doing FFI from Rust, memory accesses by C are important to consider for Stacked Borrows.</p>



<a name="168056870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168056870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168056870">(Jun 13 2019 at 15:40)</a>:</h4>
<p>they would all be "raw ptr accesses", so if the Rust code passes in raw ptrs like it should, the C code would have no restrictions</p>



<a name="168056881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168056881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168056881">(Jun 13 2019 at 15:40)</a>:</h4>
<p>I don't know, internally, the C code might do a lot of things that don't satisfy our model, but are ok in C, and that's ok as long as those don't leak to Rust.</p>



<a name="168056910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168056910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168056910">(Jun 13 2019 at 15:40)</a>:</h4>
<p>oh sure, the valgrind mode wouldnt do anything for locations not allocated by or passed to Rust</p>



<a name="168056919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168056919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168056919">(Jun 13 2019 at 15:40)</a>:</h4>
<p>I think i would prefer an hybrid only instrumenting Rust code, and then using annotations on FFI to express assumptions about what the FFI code does</p>



<a name="168056949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168056949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168056949">(Jun 13 2019 at 15:41)</a>:</h4>
<p>but inherently when doing FFI, Rust and C run on the same abstract machine.</p>



<a name="168056971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168056971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168056971">(Jun 13 2019 at 15:41)</a>:</h4>
<p>we dont have a spec for that abstract machine and probably never will^^</p>



<a name="168057052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168057052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168057052">(Jun 13 2019 at 15:42)</a>:</h4>
<p>MemorySanitizer goes a different way, instrumenting the code you compile, and then letting you use run-time instrumentation on dynamically linked code (e.g. selectively using tools similar to valgrind only for non-instrumented code, and interfacing their results with the instrumented code)</p>



<a name="168057053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168057053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168057053">(Jun 13 2019 at 15:42)</a>:</h4>
<p>but I foresee no problems with just doing stacked borrows in C, where everything is a raw ptr, no retagging ever happens -- then (UB-free) C code trivially satisfies Stacked Borrows</p>



<a name="168057113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168057113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168057113">(Jun 13 2019 at 15:42)</a>:</h4>
<p>okay I admit I have no idea how sanitizers are implemented^^</p>



<a name="168057185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168057185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168057185">(Jun 13 2019 at 15:43)</a>:</h4>
<p>but isnt the idea basically "compile to a self-checking binary"? the details of how much there are static assertions vs extra runtime in that binary dont really matter IMO, probably you need a hybrid anyway</p>



<a name="168057186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168057186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168057186">(Jun 13 2019 at 15:43)</a>:</h4>
<p><a href="http://releases.llvm.org/3.3/tools/clang/docs/MemorySanitizer.html#id7" target="_blank" title="http://releases.llvm.org/3.3/tools/clang/docs/MemorySanitizer.html#id7">http://releases.llvm.org/3.3/tools/clang/docs/MemorySanitizer.html#id7</a> - DynamoRio is what they use</p>



<a name="168057331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168057331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168057331">(Jun 13 2019 at 15:44)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> yes the idea of compiling to a self-checked binary is the same</p>



<a name="168057410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168057410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168057410">(Jun 13 2019 at 15:45)</a>:</h4>
<p>at some point you need to interface with dynamically linked C libraries, and whether those are instrumented or not, and whether the Rust instrumentation can handle either case, will depend on what we do</p>



<a name="168057554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168057554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168057554">(Jun 13 2019 at 15:47)</a>:</h4>
<p>I think that if we can get by without having to instrument external libraries, that would be a big pro</p>



<a name="168057633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168057633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168057633">(Jun 13 2019 at 15:48)</a>:</h4>
<p>E.g. annotating FFI functions with their semantics "somehow", but I don't know if this can work</p>



<a name="168057740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator%20optimization%20for%20locals%20that%20may%20not%20become%20live/near/168057740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Generator.20optimization.20for.20locals.20that.20may.20not.20become.20live.html#168057740">(Jun 13 2019 at 15:49)</a>:</h4>
<p>We are going to need such annotations for syscalls anyways (or an alternative approach, like somehow intercepting those)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>